package com.medical.doctor.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.medical.common.utils.R;
import com.medical.doctor.controller.vo.AuditVo;
import com.medical.doctor.controller.vo.DoctorInquiryVo;
import com.medical.doctor.entity.PatientMedicalRecordEntity;
import com.medical.doctor.entity.PatientPatientEntity;
import com.medical.doctor.feign.PatientMedicalRecordFeignClient;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.medical.doctor.entity.DoctorMessageEntity;
import com.medical.doctor.service.DoctorMessageService;
import com.medical.common.utils.PageUtils;



/**
 * 
 *
 * @author wen
 * @email 1023076426@qq.com
 * @date 2021-08-13 20:09:06
 */
@RestController
@RequestMapping("doctor/doctormessage")
public class DoctorMessageController {

    @Autowired
    private DoctorMessageService doctorMessageService;

    @Autowired
    private PatientMedicalRecordFeignClient client;



    /**
    * 开/关闭医生接诊
    * */
    @PostMapping("inquiry")
    public String inquiry(@RequestParam("inquiry") Integer inquiry,
                          @RequestParam("doctorId")Integer doctorId
                          ){
        return doctorMessageService.inquiry(inquiry,doctorId);
    }

    //医生登录
    @RequestMapping("/login")
    public Boolean login(@RequestParam("doctorName")String doctorName,@RequestParam("tel")String tel){
        DoctorMessageEntity doctorMessageEntity = new DoctorMessageEntity();
        if(doctorMessageEntity.getDoctorName().equals(doctorName)){
            if(doctorMessageEntity.getTel().equals("tel")){
                return true;
            }
        }
        return false;
    }


    //查询医生快速问诊的页面
    @RequestMapping("/inquirylist")
    private List<DoctorInquiryVo> inquiryVoList(@RequestBody DoctorInquiryVo inquiryVo){
        List<DoctorInquiryVo> doctorInquiryVos =  doctorMessageService.inquiryList(inquiryVo);
        return doctorInquiryVos;
    }




    /**
     *
     * Feign调用根据医师id查询医师对应患者的就诊信息
     */
    @RequestMapping("/patient/patientmedicalrecord/findByDoctorId/{doctorId}")
    public List<PatientMedicalRecordEntity> findByDoctorId(@PathVariable("doctorId") Integer doctorId){
        return client.findByDoctorId(doctorId);
    }


    /**
     * 列表
     */
    @RequestMapping("/list/{gradeId}")
    public R listByGradeId(@RequestParam Map<String, Object> params, @PathVariable("gradeId")Integer gradeId){
        PageUtils page = doctorMessageService.queryPageById(params,gradeId);

        return R.ok().put("page", page);
    }





    /**
     * 医生审核列表...
     */
    @PostMapping("/audit")
    public R audit(
            @RequestParam (value = "page",defaultValue = "1") Integer page,
            @RequestParam(value = "size",defaultValue = "3") Integer size,
            @RequestBody AuditVo data){
        IPage<AuditVo> audit = doctorMessageService.audit(page, size, data);
        PageUtils pageUtils = new PageUtils(audit);
        return R.ok().put("data",pageUtils);
    }

    /**
     * 通过Id查询某个医生注册信息回显
     */
    @GetMapping("/registration/{doctorId}")
    public R registration(@PathVariable Integer doctorId){
        AuditVo doctorMessageEntity=  doctorMessageService.registration(doctorId);
        return R.ok().put("doctorMessageEntity",doctorMessageEntity);
    }

    /**
     * 修改医生的审核状态
     */
    @RequestMapping("/status")
    public String status (
            @RequestBody DoctorMessageEntity doctorMessageEntity
    ){
        return doctorMessageService.status(doctorMessageEntity.getDoctorId(),doctorMessageEntity.getStatus(),doctorMessageEntity.getReason());
    }

    @RequestMapping("findAll")
    public R findDoctor(){
        List<DoctorMessageEntity> list = doctorMessageService.list();
        return R.ok().setData(list);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = doctorMessageService.queryPage(params);
        return R.ok().put("page",page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{doctorId}")
    public R info(@PathVariable("doctorId") Integer doctorId){
		DoctorMessageEntity doctorMessage = doctorMessageService.getById(doctorId);

        return R.ok().put("doctorMessage", doctorMessage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DoctorMessageEntity doctorMessage){
		doctorMessageService.save(doctorMessage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DoctorMessageEntity doctorMessage){
		doctorMessageService.updateById(doctorMessage);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] doctorIds){
		doctorMessageService.removeByIds(Arrays.asList(doctorIds));

        return R.ok();
    }

}
